<?php
/**
 * 汇友科技
 * @copyright (c) 2017 http://www.huiyou365.net All rights reserved.
 * @author: Creatint <creatint@163.com>
 */
namespace Admin\Controller;

class DistrictController extends AdminController{
    public function index(){
        $list = D('District')->get([]);
        $this->assign('list',$list);
        $this->assign('title','地区列表');
        $this->display();
    }

    public function edit($id = null){
        if ( IS_POST ) {
            if ( D('District')->update() ){
                $this->success('编辑成功',U('District/index'));
                redirect(U('District/index'));
            }
        } else {
            if ( $id>0 ) {
                $info = D('District')->info(['id'=>$id]);
            }
        }
        $this->assign('info',$info);
        $this->assign('title','地区编辑');
        $this->display();
    }

    public function delete($id = null){
        if ( $id ){
            $id = (array)$id;
            if ( D('District')->where(['id'=>['in',$id]])->delete() ){
                $this->success('删除成功',U('District/index'));
            } else {
                $this->error('删除失败',U('District/index'));
            }
            redirect(U('District/index'));
        } else {
            $this->error('无ID',U('District/index'));
        }
    }
}